package java_thinking.unit_8._8_3;

/**
 * @Description : JAVASE5新特性：协变返回类型 :表示在导出类中的被覆盖方法可以返回基类方法的返回类型的某种导出类型
 * @author: cww
 * @DateTime: 2019-03-01 22:34
 */

public class Grain {
    @Override
    public String toString() {
        return "Grain";
    }
    public Grain process(){
        System.out.println("Grain.process()");
        return new Grain();
    }
}
class Wheat extends Grain{
    @Override
    public String toString() {
        return "Wheat";
    }
}

class Mill{
    Grain process(){
        return new Grain();
    }
}

class WheatMill extends Mill{
    @Override
    Wheat process(){
        return new Wheat();
    }
}

/**
 * 协变返回
 */
class CovariantReturn{
    public static void main(String[] args) {
        Mill m = new Mill();
        Grain g = m.process();
        System.out.println(g);
        m = new WheatMill();
        g = m.process();
        System.out.println(g);
    }
}
